#include "GMClientAccepted.h"
#include "Factory.h"
#include "TimerMS.h"
#include "SendGameMessage.h"
#include "ClientPlayerManager.h"

#include <iostream>

GMClientAccepted::GMClientAccepted()
{
	m_id = -1;
	// spawn point
	m_pos = Vec3fNet(0.0f, 0.0f, 0.0f);
}

void GMClientAccepted::Execute()
{
	// add to the other clients draw manager
	std::cout << "clientaccepted exectued" << std::endl;
	ClientInfo info;
	info.pos = m_pos;
	TheCPManager::Instance()->AddClient(m_id, info);
}

bool GMClientAccepted::Read(SocketMessage* sm)
{
	sm->ReadInt(&m_id);
	int ts = 0;
	sm->ReadInt(&ts);
	m_timeStamp = (unsigned int)ts;
	sm->ReadFloat(&m_pos.x);
	sm->ReadFloat(&m_pos.y);
	sm->ReadFloat(&m_pos.z);
	std::cout << "Client: " << m_id << " was added" << std::endl;

	return true;
}

void GMClientAccepted::Write(SocketMessage* sm)
{
	sm->WriteString("GMClientAccepted");
	sm->WriteInt(m_id);
	sm->WriteInt(TheTimerMS::Instance()->GetTimeMS());
	sm->WriteFloat(m_pos.x);
	sm->WriteFloat(m_pos.y);
	sm->WriteFloat(m_pos.z);
}

void GMClientAccepted::SetID(int i)
{
	m_id = i;
}

int GMClientAccepted::GetID() const
{
	return m_id;
}

Vec3fNet GMClientAccepted::GetPos() const
{
	return m_pos;
}

void GMClientAccepted::SetPos(const Vec3fNet& pos)
{
	m_pos = pos;
}